package com.situ.mall.function.lambda;

public class LambdaInvokeCalc {
    public static void main(String[] args) {
        Calculator calculator = new CalculatorImpl();
        int result1 = invokeCal(120, 130, calculator);
        System.out.println("result1: " + result1);

        //匿名内部类 使用Alt+Enter: Replace with lambda优化为lambda
        int result2 = invokeCal(120, 130, new Calculator() {
            @Override
            public int cal(int a, int b) {
                return a + b;
            }
        });
        System.out.println("result2: " + result2);

        //Lambda表达式方式  Alt+Enter也可以将Lambda转换为匿名内部类
        int result3 = invokeCal(120, 130, (a, b) -> a + b);
        System.out.println("result3: " + result3);
    }

    private static int invokeCal(int a, int b, Calculator calculator) {
        return calculator.cal(a, b);
    }
}
